package acm.蓝桥杯;

import java.io.*;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class C分布式队列 {
    static int n;
    static int maxN = 10, maxOps = 2000;
    static int[] queue;

    public static void main(String[] args) {
        Reader sc = new Reader();
        n = sc.nextInt();
        queue = new int[n];
        while (sc.hasNext()) {
            String next = sc.next();
            char c = next.charAt(0);
            switch (c) {
                case 'a':
                    sc.nextInt();
                    queue[0]++;
                    break;
                case 's':
                    int fid = sc.nextInt();
                    if (queue[fid] < queue[0]) {
                        queue[fid]++;
                    }
                    break;
                case 'q':
                    int query = query();
                    System.out.println(query);
                    break;
            }
        }
    }
    public static int query() {
        int min = queue[0];
        for (int i = 1; i < n; i++) {
            min = Math.min(queue[i], min);
        }
        return min;
    }

    static
    class Reader {
        private StringTokenizer t=new StringTokenizer("");
        private BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
        private PrintWriter pr=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

        private String line(){
            try {
                return in.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
        }
        public boolean hasNext(){
            while (!t.hasMoreElements()){
                String line = line();
                if (line==null) return false;
                t=new StringTokenizer(line);
            }
            return true;
        }
        public String next(){
            hasNext();
            return t.nextToken();
        }
        public String nextLine(){
            t=new StringTokenizer("");
            return line();
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
        public long nextLong(){
            return Long.parseLong(next());
        }
        public BigInteger nextBigInteger(){
            return new BigInteger(next());
        }
    }

}
